package samples.d3.image 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.utils.setInterval;
	import graphics.raster.ComponentLabelling;
	import samples.BaseSample;
	import utils.GeomUtils;
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class ComponentLabellingSample extends BaseSample 
	{
		private var bd:BitmapData;
		private var points:Array;
		public function ComponentLabellingSample() 
		{
			
			bd = new BitmapData( 500,500, true, 0 );
			//addChild( new Bitmap( bd ) );
			
			points = new Array( new Point() );
			update();
		}
		
		private function update():void 
		{
			
			bd.perlinNoise( 100,100, 3, 0,true, true, 7, true, points );
			
			bd.threshold( bd, bd.rect, new Point(), '<=', 0xFF999999, 0 );
			bd.threshold( bd, bd.rect, new Point(), '!=', 0, 0xFFFF0000 );
			
			//bd.applyFilter( bd, bd.rect, new Point(), new GlowFilter( 0xFFFFFF, 1, 1.1, 1.1, 10, 3, true, false ) );
			
			var bmps:Vector.<Bitmap> = ComponentLabelling.process( bd );
			trace( bmps.length );
			for each( var bmp :Bitmap in bmps )
			{
				var ct:ColorTransform = new ColorTransform();
				ct.color = Math.random() * 0xFFFFFF;
				bmp.transform.colorTransform = ct;
				addChild( bmp );
			}
			center();
		}
		
	}

}